package ysq.xyg.wxapi.url;


import ysq.xyg.base.util.BaseConstant;
import ysq.xyg.base.util.BaseUtil;
import ysq.xyg.wxapi.model.base.OAuthScope;

/**
 * 微信公众号基础接口连接
 *
 * @author shengQiang yu
 * @date 2019-04-28 8:46
 */
public class WxUrlUtil {

    /**
     * 获取token接口URL
     *
     * @param appId 微信公众号 appId
     * @param appSecret 微信公众号 appSecret
     * @author shengQiang yu
     * @date 2019-04-28 8:46
     */
    public static String getTokenUrl(String appId,String appSecret){
        return String.format(TOKEN, appId, appSecret);
    }

    /**
     * 获取菜单创建接口URL
     *
     * @param token 微信公众号 accessToken
     * @author shengQiang yu
     * @date 2019-04-28 8:46
     */
    public static String getMenuCreateUrl(String token){
        return String.format(MENU_CREATE, token);
    }

    /**
     * 获取菜单删除接口URL
     *
     * @param token 微信公众号 accessToken
     * @author shengQiang yu
     * @date 2019-04-28 8:46
     */
    public static String getMenuDeleteUrl(String token){
        return String.format(MENU_DELETE, token);
    }


    /**
     * 网页授权OAuth2.0获取code
     *
     * @param appId 微信公众号 appId
     * @param redirectUrl 回调url地址
     * @param scope 回调url地址
     * @return
     * @author shengQiang yu
     * @date 2019-04-28 8:54
     */
    public static String getOAuthCodeUrl(String appId ,String redirectUrl ,String scope){
        String state=BaseConstant.OAUTH_BASE;
        if(OAuthScope.Userinfo.toString().equals(scope)){
            state= BaseConstant.OAUTH_USERINFO;
        }
        return String.format(GET_OAUTH_CODE, appId, BaseUtil.urlEnodeUTF8(redirectUrl), "code", scope, state);
    }
    /**
     * 网页授权OAuth2.0获取token接口URL
     *
     * @param appId 微信公众号 appId
     * @param appSecret 微信公众号 appSecret
     * @param code oauth2.o返回code值
     * @author shengQiang yu
     * @date 2019-04-28 8:46
     */
    public static String getOAuthTokenUrl(String appId ,String appSecret ,String code ){
        return String.format(GET_OAUTH_TOKEN, appId, appSecret, code);
    }
    /**
     * 网页授权OAuth2.0获取用户信息接口URL
     *
     * @param token OAuth2.0获取 accessToken
     * @param openid 用户openid
     * @author shengQiang yu
     * @date 2019-04-28 8:46
     */
    public static String getOAuthUserinfoUrl(String token ,String openid){
        return String.format(GET_OAUTH_USERINFO, token, openid);
    }
    /**
     * 获取发送模板消接口URL
     *
     * @param token 微信公众号 accessToken
     * @author shengQiang yu
     * @date 2019-04-28 8:46
     */
    public static String getSendTemplateMessageUrl(String token){
        return String.format(SEND_TEMPLATE_MESSAGE, token);
    }
    /**
     * 获取js ticket接口URL
     *
     * @param token 微信公众号 accessToken
     * @author shengQiang yu
     * @date 2019-04-28 8:46
     */
    public static String getJsApiTicketUrl(String token){
        return String.format(GET_JSAPI_TICKET, token);
    }

    /**
     * 获取微信支付-统一下单接口URL
     *
     * @author shengQiang yu
     * @date 2019-04-28 8:46
     */
    public static String getPayNoticeUrl(){
        return PAY_NOTICE_URL;
    }
    /**
     * 微信企业转账接口URL
     *
     * @author shengQiang yu
     * @date 2019-04-28 8:46
     */
    public static String getPayTransfers(){
        return PAY_TRANSFERS_URL;
    }


    /**
     * 小程序-获取用户信息接口URL
     *
     * @author shengQiang yu
     * @date 2019-04-28 8:46
     */
    public static String getXcxUserInfoUrl(String appId, String appSecret, String code){
        return String.format(XCX_ACCEPT_USERINFO, appId,appSecret,code);
    }

    /**
     * 小程序-获取二维码图片（二维码个数没有限制，但是传参数最多是32个字符）接口URL
     *
     * @author shengQiang yu
     * @date 2019-04-28 8:46
     */
    public static String getXcxEwmUrl(String access_token){
        return String.format(XCX_ACCEPT_EWM_URL,access_token);
    }

    /**
     * 小程序-获取二维码图片（二维码个数有限制100000，但是传参数最多是128个字符）接口URL
     *
     * @author shengQiang yu
     * @date 2019-04-28 8:46
     */
    public static String getXcxEwmXzUrl(String access_token){
        return String.format(XCX_ACCEPT_EWM_XZ_URL,access_token);
    }






    //token 接口
    protected static final String TOKEN = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s";
    //创建菜单
    private static final String MENU_CREATE = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=%s";
    //删除菜单
    private static final String MENU_DELETE = "https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=%s";
    //网页授权OAuth2.0获取code
    private static final String GET_OAUTH_CODE = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=%s&scope=%s&state=%s#wechat_redirect";

    //网页授权OAuth2.0获取token
    private static final String GET_OAUTH_TOKEN = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=%s&secret=%s&code=%s&grant_type=authorization_code";

    //网页授权OAuth2.0获取用户信息
    private static final String GET_OAUTH_USERINFO = "https://api.weixin.qq.com/sns/userinfo?access_token=%s&openid=%s&lang=zh_CN";
    //js ticket
    private static final String GET_JSAPI_TICKET="https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=%s&type=jsapi";
    //模板消息接口
    private static final String SEND_TEMPLATE_MESSAGE = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=%s";
    //微信支付-统一下单接口
    public final static String  PAY_NOTICE_URL="https://api.mch.weixin.qq.com/pay/unifiedorder";
    //微信企业转账
    public final static String  PAY_TRANSFERS_URL="https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers";
    //小程序-获取用户信息
    private static final String XCX_ACCEPT_USERINFO="https://api.weixin.qq.com/sns/jscode2session?appid=%s&secret=%s&js_code=%s&grant_type=authorization_code";
    //小程序-获取二维码图片信息
    private static final String XCX_ACCEPT_EWM_URL="https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=%s";
    //小程序-获取二维码图片信息
    private static final String XCX_ACCEPT_EWM_XZ_URL="https://api.weixin.qq.com/wxa/getwxacode?access_token=%s";


}
